#pragma once
#include <iostream>
#include <qwidget.h>
#include <qmainwindow.h>
#include <qserialport.h>
#include <vector>
#include <qlist.h>
#include <qstring.h>
#include <string>
#include <qserialport.h>
#include <qserialportinfo.h>
#include <qtextbrowser.h>
#include <qcombobox.h>
#include <qpushbutton.h>
#include <qcheckbox.h>
#include <qlineedit.h>
#include <qtabbar.h>
#include <qtablewidget.h>
#include <qprogressbar.h>
#include <qserialport.h>
#include <qserialportinfo.h>
#include <qbytearray.h>
#include <qdialog.h>
#include <qmessagebox.h>
#include <qsettings.h>
#include <qtimer.h>
#include <qvalidator.h>
#include <qfile.h>
#include <qfiledialog.h>
#include <qevent.h>
#include <CustomCombo/CustomCombo.h>
#include <qpicture.h>
#include <qpixmap.h>
#include <qsplitter.h>
#include <FileSendThread/FileSendThread.h>
#include <qtoolbutton.h>
#include <qscrollarea.h>
#include <qmenu.h>
#include <CustomAddCmdButton/CustomAddCmdButton.h>
#include <CustomToolButton/CustomToolButton.h>
#include <qlist.h>
#include <CmdJsonManager/CmdJsonManager.h>

class SerialPage :public QWidget
{
public:
	SerialPage();
	void log_test(void);
	
	void set_ui(void);

private:
	void ui_connect(void);
	void setting_init(void);
	void serial_init(void);
	void serial_send(void);
	void serial_recv(void);
	void recvMsg(void);
	void reopen_arg_changed(void);
	void open_serial(void);
	void cmd_reorganize(void);
	//bool eventFilter(QObject* obj, QEvent* ev);

	static const std::vector<QString> baud_choice;
	static const std::vector<QString> stop_choice;
	static const std::vector<QString> data_choice;
	static const std::vector<QString> parity_choice;

	QSettings* setting;
	QSerialPort* serialPort;
	QList<QSerialPortInfo> serialInfos;

	QTextBrowser* browser;
	QComboBox* baud_combo;
	QComboBox* stop_combo;
	QComboBox* data_combo;
	QComboBox* parity_combo;
	QCheckBox* hex_check;
	QCheckBox* DTR_check;
	QCheckBox* RTS_check;
	QCheckBox* auto_save_check;
	QCheckBox* timestamp_check;
	QLineEdit* time_edit;
	QCheckBox* scheduled_send;
	QLineEdit* cycle_edit;
	QLineEdit* file_choose_edit;
	QCheckBox* hex_send_check;
	QCheckBox* new_line_send_check;
	QPushButton* control_button;
	QPushButton* save_window_button;
	QPushButton* clear_recv_button;
	QPushButton* just_one_send_button;
	QPushButton* just_one_clear_send_button;
	QPushButton* choose_file_button;
	QPushButton* send_file_button;
	QPushButton* stop_send_button;
	CustomCombo* serial_choose_combo;
	QTextEdit* send_edit;
	QTimer* timer;
	QIntValidator* cycle_validator;
	QFile* file_to_send;
	QFile* file_to_save;
	QProgressBar* send_progress;
	QWidget* install_mode_bar;
	//QScrollArea* control_mode_bar;
	QWidget* control_content_widget;
	QWidget* control_content_op_widget;
	QScrollArea* control_content_cmd_scroll;
	QWidget* control_content_cmd_widget;
	CustomAddCmdButton* control_op_add_button;
	QPushButton* control_op_set_column_button;
	QLineEdit* control_op_set_column_edit;
	QWidget* help_mode_bar;
	int insert_cmd_index = 0;
	int cmd_column = 3;
	int cycle_bottom = 1;
	int cycle_top = 24 * 60 * 60 * 1000;
	QTextBrowser* help_browser;
	QLabel* help_img_label;


};